<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="_fragments::head(~{::title})">
    <meta charset="utf-8">
    <!-- 设置移动端更好的适配以及预览 -->
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>详情</title>
    <!-- 引入semantic-ui的css和js -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
    <link rel="stylesheet" href="../static/css/me.css" th:href="@{/css/me.css}"/>
    <link rel="stylesheet" href="../static/css/typo.css" th:href="@{/css/typo.css}"/>
    <link rel="stylesheet" href="../static/css/animate.css" th:href="@{/css/animate.css}"/>
    <link rel="stylesheet" href="../static/lib/prism/prism.css" th:href="@{/lib/prism/prism.css}"/>
    <!--引入css-->
    <link rel="stylesheet" href="../static/lib/tocbot/tocbot.css" th:href="/lib/tocbot/tocbot.css"/>
</head>
<body>
<!-- 导航栏部分 -->
<nav th:replace="_fragments::menu(1)" class="ui inverted attached segment m-padded-tb-mini m-shadow-small">
    <!-- inverted是反转的意思，默认效果是圆角的，我们可以使用attached是去除圆角 -->
    <div class="ui container">
        <div class="ui inverted secondary stackable menu">
            <h2 class="ui blue header item">Blog</h2>
            <a href="#" class="item menu-item m-mobile-hide"><i class="home icon"></i>首页</a>
            <a href="#" class="item menu-item m-mobile-hide"><i class="idea icon"></i>分类</a>
            <a href="#" class="item menu-item m-mobile-hide"><i class="tags icon"></i>标签</a>
            <a href="#" class="item menu-item m-mobile-hide"><i class="clone icon"></i>归档</a>
            <a href="#" class="item menu-item m-mobile-hide"><i class="info icon"></i>关于我</a>
            <div class="right item m-mobile-hide">
                <div class="ui icon inverted transparent input">
                    <input type="text" placeholder="Search..."/>
                    <i class="search  icon"></i>
                </div>
            </div>
        </div>
    </div>
    <!--绑定css样式:手机端显示，电脑端隐藏
        绑定js：当点击的时候，上面的菜单栏显示和隐藏进行切换。
    -->
    <a href="#" class="ui menu toggle black icon button m-top-right m-mobile-show">
        <i class="sidebar icon"></i>
    </a>
</nav>


<!-- 存放主体内容 -->
<div id="waypoint" class="m-padded-tb-big animated fadeIn">
    <div class="ui m-container-small">
        <div class="ui top attached segment ">
            <!--头部区域-->
            <div class="ui horizontal link list">
                <div class="item">
                    <img src="../static/images/huazai.png" th:src="@{${blog.user.avatar}}" alt=""
                         class="ui avatar image"/>
                    <div class="content">
                        <a href="#" class="header" th:text="${blog.user.nickname}">龙哥</a>
                    </div>
                </div>
                <div class="item">
                    <i class="calendar icon"></i><span th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd')}">2020-9-21</span>
                </div>
                <div class="item">
                    <i class="eye icon"></i><span th:text="${blog.views}">135</span>
                </div>
            </div>
        </div>
        <!--图片区域-->
        <div class="ui attached segment">
            <img src="../static/images/huazai.png" th:src="@{${blog.firstPicture}}" alt=""
                 class="ui rounded fluid image">
        </div>
        <!--文章内容区域-->
        <div class="ui padded attached segment">
            <div class="ui right aligned basic segment">
                <div class="ui orange basic label"><span th:text="${blog.flag}">原创</span></div>
            </div>
            <h2 class="ui centered header" th:text="${blog.title}">成功是失败之母</h2><br/>
            <div id="content" class="typo typo-selection  js-toc-content m-padded-lr-responsive"
                 th:utext="${blog.content}">


            </div>
            <!--标签-->
            <div class="m-padded-lr-responsive m-padded-tb-big">
                <div class="ui basic blue left pointing label" th:each="tag:${blog.tags}" th:text="tag.name">方法论</div>
            </div>
            <!--赞赏-->
            <div th:if="${blog.appreciation}">
                <div id="payButton" class="ui center aligned basic segment">
                    <button class="ui orange basic circular button">赞赏</button>
                </div>
                <!--赞赏的二维码-->
                <div class="ui payMoney flowing popup transition hidden">
                    <div class="ui orange basic label">
                        <div class="ui images" style="font-size: inherit!important;">
                            <div class="image">
                                <img src="../static/images/wechat.jpg" th:src="@{/images/wechat.jpg}" alt=""
                                     class="ui rounded bordered image" style="width: 125px">
                                <div>支付宝</div>
                            </div>
                            <div class="image">
                                <img src="../static/images/wechat.jpg" alt="" th:src="@{/images/wechat.jpg}"
                                     class="ui rounded bordered image" style="width: 125px">
                                <div>微信</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
        <!--博主信息部分-->
        <div class="ui attached positive message" th:if="${blog.shareStatement}">
            <div class="ui middle aligned grid">
                <div class="eleven wide column">
                    <ul class="ui list">
                        <li>作者：<span th:text="${blog.user.nickname}">龙哥</span><a href="#" target="_blank"
                                                                                 th:href="@{/about}">(联系作者)</a></li>
                        <li>发表时间：<span th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd HH:mm:ss')}">2020-1-1</span>
                        </li>
                        <li>版权声明：自由转载-非商用-非衍生-保持署名（创意共享3.0许可证）</li>
                        <li>公众号转载：请在文末添加作者公众号二维码</li>
                    </ul>
                </div>
                <div class="five wide column">
                    <img src="../static/images/wechat.jpg" th:src="@{/images/wechat.jpg}" alt=""
                         class="ui right floated rounded image" style="width: 125px">
                </div>

            </div>
        </div>

        <!--留言区域列表-->
        <div class="ui bottom attached segment" th:if="${blog.commentabled}">
            <!--留言区域-->
            <div id="comment-container" class="ui blue segment">
                <div th:fragment="commentList">
                    <div class="ui threaded comments" style="max-width: 100%">
                        <h3 class="ui dividing header">精彩评论</h3>
                        <div class="comment" th:each="comment:${comments}">
                            <a class="avatar">
                                <img src="../static/images/huazai.png" th:src="@{${comment.avatar}}" alt="">
                            </a>
                            <div class="content">
                                <a class="author">
                                    <span th:text="${comment.nickname}">Matt</span>
                                    <div class="ui mini basic teal left pointing label m-padded-mini"
                                         th:if="${comment.adminComment}">博主
                                    </div>
                                </a>
                                <div class="metadata">
                                    <span class="date"
                                          th:text="${#dates.format(comment.createTime,'yyyy-MM-dd HH:mm')}">今天下午 5:42</span>
                                </div>
                                <div class="text" th:text="${comment.content}">太赞了！</div>
                                <div class="actions">
                                    <a class="reply" data-commentid="1" data-commentnickname="Matt"
                                       th:attr="data-commentid=${comment.id},data-commentnickname=${comment.nickname}"
                                       onclick="reply(this)">回复</a>
                                </div>
                            </div>
                            <div class="comments" th:if="${#arrays.length(comment.replyComments)}>0">
                                <div class="comment" th:each="reply:${comment.replyComments}">
                                    <a class="avatar">
                                        <img src="../static/images/huazai.png" th:src="@{${reply.avatar}}" alt="">
                                    </a>
                                    <div class="content">
                                        <a class="author">
                                            <span th:text="${reply.nickname}">小红</span>
                                            <div class="ui mini basic teal left pointing label m-padded-mini"
                                                 th:if="${reply.adminComment}">博主
                                            </div>
                                            &nbsp;
                                            <span th:text="|@ ${reply.parentComment.nickname}|"
                                                  class="m-blue">@小白</span>
                                        </a>
                                        <div class="metadata">
                                            <span class="date"
                                                  th:text="${#dates.format(reply.createTime,'yyyy-MM-dd HH:mm')}">今天下午 5:42</span>
                                        </div>
                                        <div class="text" th:text="${reply.content}">太赞了！</div>
                                        <div class="actions">
                                            <a class="reply" data-commentid="1" data-commentnickname="Matt"
                                               th:attr="data-commentid=${reply.id},data-commentnickname=${reply.nickname}"
                                               onclick="reply(this)">回复</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!--/*-->
                        <div class="comment">
                            <a class="avatar">
                                <img src="../static/images/huazai.png" th:src="@{/images/huazai.png}">
                            </a>
                            <div class="content">
                                <a class="author">Elliot Fu</a>
                                <div class="metadata">
                                    <span class="date">昨天上午12:30</span>
                                </div>
                                <div class="text">
                                    <p>這對我的研究是非常有用.謝謝!</p>
                                </div>
                                <div class="actions">
                                    <a class="reply">回复</a>
                                </div>
                            </div>
                            <div class="comments">
                                <div class="comment">
                                    <a class="avatar">
                                        <img src="../static/images/huazai.png" th:src="@{/images/huazai.png}">
                                    </a>
                                    <div class="content">
                                        <a class="author">Jenny Hess</a>
                                        <div class="metadata">
                                            <span class="date">刚刚</span>
                                        </div>
                                        <div class="text">艾略特你永远是多么正确 :)</div>
                                        <div class="actions">
                                            <a class="reply">回复</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="comment">
                            <a class="avatar">
                                <img src="../static/images/huazai.png" th:src="@{/images/huazai.png}">
                            </a>
                            <div class="content">
                                <a class="author">Joe Henderson</a>
                                <div class="metadata">
                                    <span class="date">5 天以前</span>
                                </div>
                                <div class="text">老兄，这太棒了。非常感谢。</div>
                                <div class="actions">
                                    <a class="reply">回复</a>
                                </div>
                            </div>
                        </div>
                        <!--*/-->
                    </div>
                </div>

            </div>
            <!--书写评论区-->
            <div id="comment-form" class="ui form">
                <input type="hidden" name="blog.id" th:value="${blog.id}">
                <input type="hidden" name="parentComment.id" value="-1">
                <div class="field">
                    <textarea name="content" placeholder="请输入评论信息..."></textarea>
                </div>
                <div class="fields">
                    <div class="field m-mobile-wide m-margin-bottom-small">
                        <div class="ui left icon input">
                            <i class="user icon"></i>
                            <input type="text" name="nickname" placeholder="姓名"
                                   th:value="${session.user}!=null?${session.user.nickname}:''">
                        </div>
                    </div>
                    <div class="field m-mobile-wide m-margin-bottom-small">
                        <div class="ui left icon input">
                            <i class="mail icon"></i>
                            <input type="text" name="email" placeholder="邮箱"
                                   th:value="${session.user}!=null?${session.user.email}:''">
                        </div>
                    </div>
                    <div class="field m-mobile-wide m-margin-bottom-small">
                        <button id="commentpost-btn" type="button" class="ui m-mobile-wide blue basic button"><i
                                class="rocket icon"></i>发布
                        </button>
                    </div>

                </div>
                <div class="ui error message"></div>
            </div>

        </div>
    </div>

</div>

<!--右侧悬浮小图标-->
<div id="toolbar" class="m-right-bottom m-fixed m-padded-mini m-padded hidden">
    <div class="ui vertical icon buttons ">
        <button type="button" class="ui toc-btn blue button">目录</button>
        <a href="#comment-container" type="button" class="ui blue button">留言</a>
        <button class="ui wechat green basic icon button"><i class="wechat icon"></i></button>
        <!--点击直接跳到顶部-->
        <div id="toTop-button" class="ui basic button"><i class="chevron up icon"></i></div>
    </div>
</div>
<!--点击生成目录-->
<div class="ui toc-container flowing popup transition hidden" style="width: 250px">
    <ol class="js-toc">

    </ol>
</div>
<!--点击生成微信二维码-->
<div id="qrcode" class="ui wechat-qr flowing popup transition hidden" style="width: 130px">
    <!--<img src="./static/images/wechat.jpg" alt="" class="ui rounded bordered image" style="width: 120px">-->
</div>
<br/>
<br/>

<!-- 存放底部footer -->
<!-- vertical:垂直的，默认情况下segment是圆角，-->
<footer th:replace="_fragments::footer" class="ui inverted vertical segment m-padded-tb-big">
    <!--设置一个居中的容器-->
    <div class="ui center aligned container">
        <!--grid:垂直划分，默认是16份；
            inverted divided：采用分割线  -->
        <div class="ui inverted stackable divided grid">
            <!--存放左边的二维码-->
            <diV class="three wide column">
                <div class="ui inverted link list">
                    <div class="item">
                        <!--rounded：设置图片为圆角-->
                        <img src="../static/images/wechat.jpg" class="ui rounded image" alt="图片加载失败"
                             style="width: 100px;height: 100px;"/>
                    </div>
                </div>
            </diV>
            <!--存放最新博客的信息-->
            <diV class="three wide column">
                <h4 class="ui inverted header  m-text-spaced m-opacity-mini">最新博客</h4>
                <div class="ui inverted link list">
                    <a href="#" class="item">用户故事</a>
                    <a href="#" class="item">早期的鸟儿有虫吃</a>
                    <a href="#" class="item">早期的虫儿被鸟吃</a>
                </div>
            </diV>
            <!--存放联系我的相关信息-->
            <diV class="three wide column">
                <h4 class="ui inverted header m-text-spaced m-opacity-mini">联系我</h4>
                <div class="ui inverted link list">
                    <a href="#" class="item">Email：p15194420545@163.com</a>
                    <a href="#" class="item">QQ：1753853993</a>
                </div>
            </diV>
            <!--右侧的论坛介绍-->
            <diV class="seven wide column">
                <h4 class="ui inverted header m-text-spaced m-opacity-mini">论坛show</h4>
                <p class=" m-opacity-mini">这是我的个人博客，会分享一些关于编程，写作，思考相关的内容，希望可以给来到这里的人有所帮助...</p>
            </diV>
        </div>
        <div class="ui inverted section divider"></div>
        <p class="m-text-thin m-text-spaced m-opacity-tiny">Copyright © 2016 - 2017 Lirenmi Designed by Lirenmi</p>
    </div>

</footer>

<th:block th:replace="_fragments::script">
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>
    <script src="//cdn.jsdelivr.net/npm/jquery.scrollto@2.1.2/jquery.scrollTo.min.js"></script>
    <script src="../static/lib/prism/prism.js" th:src="@{/lib/prism/prism.js}"></script>
    <script src="../static/lib/qrcode/qrcode.js" th:src="@{/lib/qrcode/qrcode.js}"></script>
    <script src="../static/lib/tocbot/tocbot.js" th:src="@{/lib/tocbot/tocbot.js}"></script>
    <script src="../static/lib/waypoints/jquery.waypoints.js" th:src="@{/lib/waypoints/jquery.waypoints.js}"></script>
</th:block>

<!--在javascript中取值需要加上inline才有效-->
<script type="text/javascript" th:inline="javascript">
    $('.menu.toggle').click(function () {
        $('.menu-item').toggleClass('m-mobile-hide');
    });
    $('#payButton').popup({
        /*定义作用的区域*/
        popup: $('.payMoney.popup'),
        on: 'click',
        /*弹出位置是按钮中央*/
        position: 'bottom center'
    });
    /*初始化目录插件*/
    tocbot.init({
        // Where to render the table of contents.
        tocSelector: '.js-toc',
        // Where to grab the headings to build the table of contents.
        contentSelector: '.js-toc-content',
        // Which headings to grab inside of the contentSelector element.
        headingSelector: 'h1, h2, h3',
    });
    /*点击目录：生成目录*/
    $('.toc-btn').popup({
        popup: $('.ui.toc-container.popup'),
        on: 'click',
        position: 'left center'
    });
    $('.ui.wechat').popup({
        /*定义作用的区域*/
        popup: $('.wechat-qr'),
        /*弹出位置是按钮中央*/
        position: 'left center'
    });
    /*二维码生成，扫描进入链接*/
    var serverUrl =/*[[#{serverUrl}]]*/"127.0.0.1:8080"
    var url =/*[[@{/blog/{id}(id=${blog.id})}]]*/"";
    var qrcode = new QRCode("qrcode", {
        text: serverUrl + url,
        width: 110,
        height: 110,
        colorDark: "#000000",
        colorLight: "#ffffff",
        correctLevel: QRCode.CorrectLevel.H
    });
    /*控制平滑滚动*/
    $('#toTop-button').click(function () {
        $(window).scrollTo(0, 500);
    });
    /*初始化检测*/
    var waypoint = new Waypoint({
        /*目标点：需要监测哪一个*/
        element: document.getElementById('waypoint'),
        /*处理方式：按照方向*/
        handler: function (direction) {
            if (direction == 'down') {
                $('#toolbar').show(100);
            } else {
                $('#toolbar').hide(500);
            }
            console.log('Scrolled to waypoint!  ' + direction);
        }
    })
    $('.ui.form').form({
        fields: {
            title: {
                identifier: 'content',
                rules: [{
                    type: 'empty',
                    prompt: '请输入评论的内容'
                }]

            },
            content: {
                identifier: 'nickname',
                rules: [{
                    type: 'empty',
                    prompt: '标题：请输入你的昵称'
                }]
            },
            type: {
                identifier: 'email',
                rules: [{
                    type: 'email',
                    prompt: '请填写正确的邮箱地址'
                }]
            }
        }
    });
    $('#commentpost-btn').click(function () {
        var boo = $('.ui.form').form('validate form');
        if (boo) {
            console.log("验证通过");
            postData();
        } else {
            console.log("验证不通过");
        }
    })
    $(function () {
        init();
    })

    function init() {
        $("#comment-container").load(/*[[@{/comments/{blogId}(blogId=${blog.id})}]]*/)
    }

    /*页面一加载需要调用一次postData方法*/
    function postData() {
        $("#comment-container").load(/*[[@{/comments}]]*/"", {
            //获取需要提交的内容
            "parentComment.id": $("[name='parentComment.id']").val(),
            "blog.id": $("[name='blog.id']").val(),
            "nickname": $("[name='nickname']").val(),
            "email": $("[name='email']").val(),
            "content": $("[name='content']").val(),
        }, function (responseTxt, statusTxt, xhr) {
            $(window).scrollTo($("#comment-container"), 500);
            //清空表单
            clearContent();
        })
    }

    function clearContent() {
        $("[name='content']").val('');
        $("[name='parentComment.id']").val(-1);
        $("[name='content']").attr("placeholder", "请输入评论信息...");

    }

    function reply(obj) {
        var commentId = $(obj).data('commentid');
        var commentNickname = $(obj).data('commentnickname');
        $("[name='content']").attr("placeholder", "@" + commentNickname).focus();
        $("[name='parentComment.id']").val(commentId);
        $(window).scrollTo($("#comment-form"), 500);

    }


</script>
</body>
</html>
